class MyStack:
    def __init__(self):
        self.stack=[]

    def push(self,item):
        """
        压栈
        :param item:
        :return:
        """
        self.stack.append(item)

    def pop(self):
        """
        出栈
        :return:
        """
        return self.stack.pop()

    def top(self):
        return f"栈顶元素{self.stack[-1]}"

    def length(self):
        """
        栈长度
        :return:
        """
        return len(self.stack)

    def is_empty(self):
        """
        判空
        :return:
        """
        return len(self.stack)==0

def simulate_function_call():
    call_stack = MyStack()
    # 模拟函数调用
    functions = ["func1", "func2", "func3"]
    for func in functions:
        call_stack.push(func)
    # 模拟函数执行结束并从栈中弹出
    while not call_stack.is_empty():
        current_function = call_stack.pop()
        print(f"函数执行结束: {current_function}")

def is_parentheses_balanced(expression):
    stack=MyStack()
    pairs={")":"("}
    for char in expression:
        if char in pairs.values():
            stack.push(char)
        elif char in pairs.keys():
            if  stack.is_empty() or stack.pop()!=pairs[char]:
                return False
    return stack.is_empty()


if __name__ == '__main__':
    simulate_function_call()


    expressions = ["(())", "((()))", "(()", ")(", "(a + b) * (c - d)"]
    for expr in expressions:
        print(f"表达式 '{expr}' 的括号匹配: {is_parentheses_balanced(expr)}")